<template>
	<!-- 钻石商城  diamondMall-->
	<view class="">
		<view class="diamondMall_head flex1 flex-between p20">
			<view class="">
				<u-icon @click=backhomeindex() class="size-40" name="arrow-left"></u-icon>
			</view>
			<view class="size-30 fw ml-60 mycustomer_head">
				{{show_name}}
				 
			</view>
			<view class="">
				<u-icon @click="friendDetail(user_id,list_id,show_name)" class="size-40" name="more-dot-fill"></u-icon>
			</view>
		</view>
		<view class="" style="background-color: rgb(240, 239, 244);">
			<scroll-view scroll-with-animation="true" style="height: 1240rpx;" scroll-y="true" :scroll-top="scrollTop">
				<view class="numbersbox flex flex-start ptb-10 plr-10" v-if="this.name=='群聊'">
					<image :src="'http://im.ezongguan.com/static/photo/'+item.photo" mode="" v-for="item in numberList">
					</image>
				</view>
				<view class=" mt-60 p10  " v-for="(item,index) in chatMessages" style="" @longpress="longpress(item)">
					<view :style="{float:item.msg.user_info.uid ==obj?'left':'right'}" class="flex1"
						style="align-items: center;">
						<image v-if="item.msg.user_info.uid==obj" class=""
							:src="'http://im.ezongguan.com/static/photo/' +item.msg.user_info.face" mode=""
							style="width: 60rpx;height: 60rpx;border-radius: 50%;">
						</image>
					<!-- 	<view class="size-26"
							style="background-color: #ECECEC;padding: 20rpx;border-radius: 20rpx 0px 20rpx 20rpx;margin: 0 20rpx 0px 20rpx;word-wrap: break-word;word-break: normal;max-width: 460rpx;">
							{{item.msg.content.text}}
						</view> -->
						<rich-text :nodes="messageemoj(item.msg.content.text)"></rich-text>
						<image v-if="item.msg.user_info.uid!=obj" class=""
							:src="'http://im.ezongguan.com/static/photo/' +item.msg.user_info.face" mode=""
							style="width: 60rpx;height: 60rpx;border-radius: 50%;">
						</image>

					</view>
					 <!-- <image :src="abc" mode="" style="width: 40rpx;height: 40rpx;"></image> -->
				</view>
                 
			</scroll-view>
		</view>

		<view class="mycustomer_bottom flex1"
			style="align-items: center;justify-content: space-evenly;background-color: #E9E9E9;"
			:style="{ transform: mix? 'translateY(0rpx)':'translateY(300rpx)'}">
			<view class="flex1 mt-20" style="height:380rpx;">

				<view class="">
					<image :src="luyinsrc" mode="widthFix" style="width: 50rpx;" @click="record"></image>
				</view>
				<view class="">
					<input maxlength=99999 @input="input" v-model="value1" @confirm=enter :placeholder=placeholder
						placeholder-style='text-align:center' :disabled="disabled"
						style="background-color: #FFF;width: 500rpx;height: 60rpx;;border-radius: 10rpx;margin: 0 0 0 0;" />
				</view>
				<view class="">
					<image @click="emoticon" src="../../static/my/my_weixiao.png" mode="widthFix" style="width: 50rpx;">
					</image>
				</view>
				<view class="send" @click="handsend()">
					发送
				</view>
				<view class="absolute mt-80 emoticontext_one" style="" v-if="transform=mix" style="">
					<swiper class="emoji-box" indicator-dots="true" duration="150">
						<swiper-item class="emoji-page" v-for="(page,pid) in emojiList" :key="pid"
							style="display: flex;flex-wrap: wrap;">
							<view class="emoji-icon ml-30" v-for="(em,eid) in page" :key="eid" @tap="addEmoji(em)">
								<image :src="'/static/img/emoji/'+em.url" style="width: 50rpx;height: 50rpx;"></image>
							</view>
						</swiper-item>
					</swiper>
				</view>
			</view>
		</view>
		<u-popup v-model="show" mode="center" :mask='false'>
			<view class="p10" style="line-height: 60rpx;">
				<view :class="[item.active==true?'selectitem':'selectitem1']" v-for="item in ribbonlist"
					@click="handleribbonlist(item)">
					{{item.name}}
				</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	export default {
		components: {},

		data() {
			return {
				emojiList: [
					[{
						"url": "100.gif",
						alt: "[微笑]"
					}, {
						"url": "101.gif",
						alt: "[伤心]"
					}, {
						"url": "102.gif",
						alt: "[美女]"
					}, {
						"url": "103.gif",
						alt: "[发呆]"
					}, {
						"url": "104.gif",
						alt: "[墨镜]"
					}, {
						"url": "105.gif",
						alt: "[哭]"
					}, {
						"url": "106.gif",
						alt: "[羞]"
					}, {
						"url": "107.gif",
						alt: "[哑]"
					}, {
						"url": "108.gif",
						alt: "[睡]"
					}, {
						"url": "109.gif",
						alt: "[哭]"
					}, {
						"url": "110.gif",
						alt: "[囧]"
					}, {
						"url": "111.gif",
						alt: "[怒]"
					}, {
						"url": "112.gif",
						alt: "[调皮]"
					}, {
						"url": "113.gif",
						alt: "[笑]"
					}, {
						"url": "114.gif",
						alt: "[惊讶]"
					}, {
						"url": "115.gif",
						alt: "[难过]"
					}, {
						"url": "116.gif",
						alt: "[酷]"
					}, {
						"url": "117.gif",
						alt: "[汗]"
					}, {
						"url": "118.gif",
						alt: "[抓狂]"
					}, {
						"url": "119.gif",
						alt: "[吐]"
					}, {
						"url": "120.gif",
						alt: "[笑]"
					}, {
						"url": "121.gif",
						alt: "[快乐]"
					}, {
						"url": "122.gif",
						alt: "[奇]"
					}, {
						"url": "123.gif",
						alt: "[傲]"
					}],
					[{
						"url": "124.gif",
						alt: "[饿]"
					}, {
						"url": "125.gif",
						alt: "[累]"
					}, {
						"url": "126.gif",
						alt: "[吓]"
					}, {
						"url": "127.gif",
						alt: "[汗]"
					}, {
						"url": "128.gif",
						alt: "[高兴]"
					}, {
						"url": "129.gif",
						alt: "[闲]"
					}, {
						"url": "130.gif",
						alt: "[努力]"
					}, {
						"url": "131.gif",
						alt: "[骂]"
					}, {
						"url": "132.gif",
						alt: "[疑问]"
					}, {
						"url": "133.gif",
						alt: "[秘密]"
					}, {
						"url": "134.gif",
						alt: "[乱]"
					}, {
						"url": "135.gif",
						alt: "[疯]"
					}, {
						"url": "136.gif",
						alt: "[哀]"
					}, {
						"url": "137.gif",
						alt: "[鬼]"
					}, {
						"url": "138.gif",
						alt: "[打击]"
					}, {
						"url": "139.gif",
						alt: "[bye]"
					}, {
						"url": "140.gif",
						alt: "[汗]"
					}, {
						"url": "141.gif",
						alt: "[抠]"
					}, {
						"url": "142.gif",
						alt: "[鼓掌]"
					}, {
						"url": "143.gif",
						alt: "[糟糕]"
					}, {
						"url": "144.gif",
						alt: "[恶搞]"
					}, {
						"url": "145.gif",
						alt: "[什么]"
					}, {
						"url": "146.gif",
						alt: "[什么]"
					}, {
						"url": "147.gif",
						alt: "[累]"
					}],
					[{
						"url": "148.gif",
						alt: "[看]"
					}, {
						"url": "149.gif",
						alt: "[难过]"
					}, {
						"url": "150.gif",
						alt: "[难过]"
					}, {
						"url": "151.gif",
						alt: "[坏]"
					}, {
						"url": "152.gif",
						alt: "[亲]"
					}, {
						"url": "153.gif",
						alt: "[吓]"
					}, {
						"url": "154.gif",
						alt: "[可怜]"
					}, {
						"url": "155.gif",
						alt: "[刀]"
					}, {
						"url": "156.gif",
						alt: "[水果]"
					}, {
						"url": "157.gif",
						alt: "[酒]"
					}, {
						"url": "158.gif",
						alt: "[篮球]"
					}, {
						"url": "159.gif",
						alt: "[乒乓]"
					}, {
						"url": "160.gif",
						alt: "[咖啡]"
					}, {
						"url": "161.gif",
						alt: "[美食]"
					}, {
						"url": "162.gif",
						alt: "[动物]"
					}, {
						"url": "163.gif",
						alt: "[鲜花]"
					}, {
						"url": "164.gif",
						alt: "[枯]"
					}, {
						"url": "165.gif",
						alt: "[唇]"
					}, {
						"url": "166.gif",
						alt: "[爱]"
					}, {
						"url": "167.gif",
						alt: "[分手]"
					}, {
						"url": "168.gif",
						alt: "[生日]"
					}, {
						"url": "169.gif",
						alt: "[电]"
					}, {
						"url": "170.gif",
						alt: "[炸弹]"
					}, {
						"url": "171.gif",
						alt: "[刀子]"
					}],
					[{
						"url": "172.gif",
						alt: "[足球]"
					}, {
						"url": "173.gif",
						alt: "[瓢虫]"
					}, {
						"url": "174.gif",
						alt: "[翔]"
					}, {
						"url": "175.gif",
						alt: "[月亮]"
					}, {
						"url": "176.gif",
						alt: "[太阳]"
					}, {
						"url": "177.gif",
						alt: "[礼物]"
					}, {
						"url": "178.gif",
						alt: "[抱抱]"
					}, {
						"url": "179.gif",
						alt: "[拇指]"
					}, {
						"url": "180.gif",
						alt: "[贬低]"
					}, {
						"url": "181.gif",
						alt: "[握手]"
					}, {
						"url": "182.gif",
						alt: "[剪刀手]"
					}, {
						"url": "183.gif",
						alt: "[抱拳]"
					}, {
						"url": "184.gif",
						alt: "[勾引]"
					}, {
						"url": "185.gif",
						alt: "[拳头]"
					}, {
						"url": "186.gif",
						alt: "[小拇指]"
					}, {
						"url": "187.gif",
						alt: "[拇指八]"
					}, {
						"url": "188.gif",
						alt: "[食指]"
					}, {
						"url": "189.gif",
						alt: "[ok]"
					}, {
						"url": "190.gif",
						alt: "[情侣]"
					}, {
						"url": "191.gif",
						alt: "[爱心]"
					}, {
						"url": "192.gif",
						alt: "[蹦哒]"
					}, {
						"url": "193.gif",
						alt: "[颤抖]"
					}, {
						"url": "194.gif",
						alt: "[怄气]"
					}, {
						"url": "195.gif",
						alt: "[跳舞]"
					}],
					[{
						"url": "196.gif",
						alt: "[发呆]"
					}, {
						"url": "197.gif",
						alt: "[背着]"
					}, {
						"url": "198.gif",
						alt: "[伸手]"
					}, {
						"url": "199.gif",
						alt: "[耍帅]"
					}, {
						"url": "200.png",
						alt: "[微笑]"
					}, {
						"url": "201.png",
						alt: "[生病]"
					}, {
						"url": "202.png",
						alt: "[哭泣]"
					}, {
						"url": "203.png",
						alt: "[吐舌]"
					}, {
						"url": "204.png",
						alt: "[迷糊]"
					}, {
						"url": "205.png",
						alt: "[瞪眼]"
					}, {
						"url": "206.png",
						alt: "[恐怖]"
					}, {
						"url": "207.png",
						alt: "[忧愁]"
					}, {
						"url": "208.png",
						alt: "[眨眉]"
					}, {
						"url": "209.png",
						alt: "[闭眼]"
					}, {
						"url": "210.png",
						alt: "[鄙视]"
					}, {
						"url": "211.png",
						alt: "[阴暗]"
					}, {
						"url": "212.png",
						alt: "[小鬼]"
					}, {
						"url": "213.png",
						alt: "[礼物]"
					}, {
						"url": "214.png",
						alt: "[拜佛]"
					}, {
						"url": "215.png",
						alt: "[力量]"
					}, {
						"url": "216.png",
						alt: "[金钱]"
					}, {
						"url": "217.png",
						alt: "[蛋糕]"
					}, {
						"url": "218.png",
						alt: "[彩带]"
					}, {
						"url": "219.png",
						alt: "[礼物]"
					}, ]
				],
				emoji:{"[微笑]":"100.gif"},
				mix: false,
				showemoticon: false,
				setIntervalist: '',
				ribbonlist: [{
						name: '复制',
						id: 0,
						active: 'flase'
					},
					{
						name: '发送给朋友',
						id: 1,
						active: 'flase'
					}, {
						name: '收藏',
						id: 2,
						active: 'flase'
					}, {
						name: '删除',
						id: 3,
						active: 'flase'
					}, {
						name: '多选',
						id: 4,
						active: 'flase'
					}, {
						name: '撤回',
						id: 5,
						active: 'flase'
					},
				],
				show: false,
				disabled: false,
				luyinsrc: '../../static/my/my_luyin.png',
				placeholder: '',
				time: 0,
				obj: '',
				pageList: [],
				pageList1: [],
				pageList2: [],
				valueInput: '',
				value1: '',
				scrollTop: 0,
				list_id: '',
				name: '',
				numberList: '',
				chatMessages: [],
				user_id: '',
				show_name: ',',
				// timeout: 10000,
				// timeoutObj: null,
				socketOpen: false,
				socketid: '',
				arr: [],
				abc: '',
				sendem:[],

			}

		},
		computed:{
			messageemoj(){
				return function(message){
					message.length
					let msg ='';
					let bgn = message.indexOf("[")
					let end = message.indexOf("]")
					let iq = 0
					//死循环
					while(bgn !=-1&&end !=-1){
						iq += 1;
						//不存在跳出
						if(bgn ==-1||end ==-1){
							msg+= message
							break;
						}
						//防止死循环
						if(iq>99){
							break;
						}
						//是否是表情格式
						if(bgn < end&&end<=bgn+3){
							let ok = false
							for(let i = 0;i < this.emojiList.length; i++){
								//匹配到表情退出
								if(ok){
									break;
								}
								//未匹配到表情退出
								if(i == this.emojiList.length){
									msg+= message.substring(0,message.indexOf("]"));
									message = message.substring(message.indexOf("]")+1);
									break;
								}
								for(let j = 0; j < this.emojiList[i].length; j++){
									if(this.emojiList[i][j].alt == message.substring(message.indexOf("["),message.indexOf("]")+1)){
									//匹配表情替换
										msg+= message.substring(0,message.indexOf("["));
										//格式很重要，不要出现"",用''
										msg+= "<img src='' style='width: 50rpx;height: 50rpx;display:inline-block;' />"  
										message = message.substring(message.indexOf("]")+1);
										ok = true;
										break;
									}
								}
							}
						}else{
							msg+= message.substring(0,message.indexOf("["));
							message = message.substring(message.indexOf("[")+1);
						}
						//从新获取
						bgn = message.indexOf("[")
						end = message.indexOf("]")
						// break
					}
					if(bgn ==-1||end ==-1){
					//消息不存在表情格式，直接赋值
						if(msg.length==0){
							msg = message
						}
						
					}
					return msg
				}
						}
		},
		onShow() {
			// this.getMemberPhotos()
			// this.getChatDetails()
			// this.chatData()
			// this.setchat()
			// this.openConnection()
			// this.onSocketMessage()
		},
		onPageScroll: function(e) { //nvue暂不支持滚动监听，可用bindingx代替
			// console.log("滚动距离为：" + e.scrollTop);
		},
		onLoad(options) {
			console.log(options);
			this.list_id = options.list_id
			this.show_name = options.show_name
			console.log(this.show_name);
		},
		onHide() {
			// clearInterval(this.setIntervalist)
			// this.setIntervalist = null
			// console.log('onHide');
		},
		onUnload() {
			// clearInterval(this.setIntervalist)
			// this.setIntervalist = null
			// console.log('onUnload');
		},
		created() {
			this.getMemberPhotos()
			this.getChatDetails()
			this.openConnection()
			this.onSocketMessage()
			this.chatData()
		},
		methods: {
			// 发送按钮
			handsend() {	 
				
				    this.valuesend = this.value1
					console.log(this.valuesend);
					// let abc = ''
					// console.log(`${'/static/img/emoji/'}`+this.sendem.url);
					// this.abc = `${'/static/img/emoji/'}` + this.sendem.url
					
					// console.log(abc);
				// this.value1=null
				if (this.value1 == '') {
					uni.showToast({
						title: '请输入文字',
						icon: 'none'
					})
				} else {
					var params = {
						_token: uni.getStorageSync('im_token'),
						_agent_id: '1',
						content_type: 0,
						content: `{"text":"${this.valuesend}"}`,
						list_id: this.list_id,
					}
					uni.request({
						url: `http://im.ezongguan.com/im/message/textMsg`,
						method: 'POST',
						data: params,
						success: (res) => {
							console.log(res)
							if (this.socketOpen) {
								console.log("this.socketOpen", this.socketOpen)
								uni.sendSocketMessage({
									data: this.valueInput,
								})
								this.chatData()
							} else {
								console.log("this.socketOpen", this.socketOpen)
								uni.onSocketOpen(res => {
									this.socketOpen = true;
									uni.sendSocketMessage({
										data: this.valueInput,
									})
								})
								this.chatData()
							}
						},
					})
					this.value1 = ''
				}

			},
			//添加表情
			addEmoji(em) {
				console.log(em);
			  this.sendem=em
				this.value1 += em.alt;

			},
			// Websocket
			openConnection() {
				// 打开连接
				// uni.closeSocket(); // 确保已经关闭后再重新打开
				uni.connectSocket({
					url: 'ws://im.ezongguan.com:8383',
					success(res) {
						console.log('WebSocket连接成功 connectSocket=', res);
					},
					fail(err) {
						console.log('WebSocket连接失败 connectSocket=', err);
					}
				});

				//监听连接成功
				uni.onSocketOpen(res => {
					// this.onSocketMessage(); // 打开成功监听服务器返回的消息
					// this.socketOpen = false;
					this.socketOpen = true;
					// this.code = 'WebSocket连接成功';
					// console.log('WebSocket连接成功');
					// let data = {
					// 	content: '你好',
					// 	mode: 'heart',

					// }
					//连接成功就发检测
					//1008的报错，1000是正确
					//心跳检测成功后发消息绑定
					// 通过 WebSocket 连接发送数据
					uni.sendSocketMessage({
						data: "test"
						// data: JSON.stringify('data'),
						// success: res => {
						// 	console.log('连接中....');
						// 	data.mode = 'accept'
						// 	uni.sendSocketMessage({
						// 		data: JSON.stringify(data),
						// 		success: res => {
						// 			console.log('连接中....绑定成功',res);
						// 		},
						// 	});
						// },
						// fail: err => {
						// 	console.log('连接失败重新连接....');
						// }
					});
				});
				// uni.onSocketError(res => {
				// 	this.code = '连接打开失败';
				// 	console.log('WebSocket连接打开失败，请检查！');
				// });
				// uni.onSocketClose(res => {
				// 	this.code = '连接已关闭';
				// 	// clearInterval(this.timeoutObj);
				// 	console.log('WebSocket 已关闭！');
				// });

			},
			//	打开成功监听服务器返回的消息  监听WebSocket接受到服务器的消息事件
			onSocketMessage() {
				// console.log(111);
				// 消息
				// this.timeout = 10000;
				// this.timeoutObj = null;
				//监听WebSocket连接打开事件。
				uni.onSocketMessage(res => {
					console.log("onSocketMessage", res);
					// this.socketid=JSON.parse(res.data).data.client_id
					// this.socketOpen = true;
					this.getSocketMsg(JSON.parse(res.data)); // 监听到有新服务器消息
				});
			},
			// 监听到有新服务器消息
			getSocketMsg(reData) {
				// 监听到服务器消息
				console.log('reData', reData);
				// console.log('收到服务器消息', reData.data.client_id);
				// if (reData.errcode == 1000) {
				// 	this.code = '连接中'
				// } else if (reData.errcode == 1008) {
				// 	this.code = '连接断开'
				// }
				// this.reset(); // 检测心跳reset,防止长时间连接导致连接关闭
			},
			// 检测心跳reset
			reset() {
				// clearInterval(this.timeoutObj);
				this.start(); // 启动心跳
			},
			// 启动心跳 start
			start() {
				let data = {
					content: '你好',
					mode: 'heart',
					user_id: this.list_id
				}
				// this.timeoutObj = setInterval(() => {
				//1008的报错，1000是正确
				uni.sendSocketMessage({
					data: JSON.stringify(data),
					success: res => {
						console.log('连接中....');
						this.chatData()

					},
					fail: err => {
						console.log('连接失败重新连接....');
						this.openConnection();
					}
				});
				// }, this.timeout);
			},
			// setchat() {
			// 	this.setIntervalist=setInterval(() => {
			// 		this.chatData()
			// 	}, 30000)
			// },
			// Websocket

			// 撤回
			withdraw() {
				console.log(this.msg_id);
				this.msg_id = this.msg_id
				var params = {
					list_id: this.list_id,
					_token: uni.getStorageSync('im_token'),
					_agent_id: '1',
					msg_id: this.msg_id,
					type: '0'
				}
				uni.request({
					url: `http://im.ezongguan.com/im/message/withdraw`,
					method: 'POST',
					data: params,
					success: (res) => {
						console.log(res)
						if (res.data.err == 1) {
							uni.showToast({
								title: res.data.msg,
								icon: 'none'
							})
						} else if (res.data.err == 0) {
							uni.showToast({
								title: res.data.msg,
								icon: 'none'
							})
						}
						this.chatData()
					},
				})

			},
			// 功能区按钮事件
			handleribbonlist(item) {
				console.log(item);
				this.ribbonlist.forEach((item) => {
					item.active = false
				})
				item.active = true
				if (item.id == 5) {
					this.withdraw()
				}
			},
			// 长按功能区事件
			longpress(item) {
				console.log(item.msg.id);
				this.msg_id = item.msg.id
				console.log(111);
				this.show = true
			},
			record() {
				this.time++
				console.log(this.time)
				if ((this.time) % 2 == 0) {
					this.luyinsrc = '../../static/my/my_luyin.png'
					this.placeholder = ''
					this.disabled = false
					console.log(1);
				} else {
					this.luyinsrc = '../../static/my/my_luyin1.png'
					this.placeholder = '按住说话'
					this.disabled = true
					console.log(2);
				}
			},
			// 右上控件
			friendDetail(user_id, list_id, show_name) {
				if (this.obj == 0) {
					console.log('这是群聊');
					uni.navigateTo({
						url: '../chip/friendDetail?user_id=' + user_id + '&list_id=' + list_id + '&show_name=' +
							show_name + '&newsdetail=' + 1
					})
				} else {
					console.log('这是私聊');
					uni.navigateTo({
						url: '../chip/personalDetail?user_id=' + user_id + '&list_id=' + list_id + '&show_name=' +
							show_name + '&newsdetail=' + 1
					})
				}
			},
			// 获得当前会话内容
			chatData() {
				// this.getChatDetails()
				var params = {
					list_id: this.list_id,
					_token: uni.getStorageSync('im_token'),
					_agent_id: '1',
					time: 0,
					is_up: 1
				}
				uni.request({
					url: `http://im.ezongguan.com/im/get/chatData`,
					method: 'POST',
					data: params,
					success: (res) => {
						console.log(res.data.data);
						// this.obj_id=
						// this.numberList=res.data.data
						this.chatMessages = res.data.data.list
						this.obj = res.data.data.obj_id
						// console.log(this.obj); 
						// console.log(this.chatMessages)
						this.pageList1 = []
						this.pageList2 = []
						for (let i = 0; i < this.chatMessages.length; i++) {
							// console.log(this.chatMessages[i].msg.user_info.uid,"user_info.uid")
							// console.log(this.user_id,"user_id")
							if (this.chatMessages[i].msg.user_info.uid == this.obj) {
								this.pageList1.push(this.chatMessages[i])
							} else {
								this.pageList2.push(this.chatMessages[i])
							}

							// console.log(this.pageList1)
							// console.log(this.pageList2)
						}
					},
				})
			},
			// 会话窗口获取成员头像
			getMemberPhotos() {
				var params = {
					list_id: this.list_id,
					_token: uni.getStorageSync('im_token'),
					_agent_id: '1'
				}
				uni.request({
					url: `http://im.ezongguan.com/im/vendor/getMemberPhotos`,
					method: 'POST',
					data: params,
					success: (res) => {
						this.numberList = res.data.data
						// console.log(this.numberList)
					},
				})
			},
			// 获得会话详情
			getChatDetails() {
				var params = {
					list_id: this.list_id,
					_token: uni.getStorageSync('im_token'),
					_agent_id: '1'
				}
				uni.request({
					url: `http://im.ezongguan.com/im/message/getChatDetails`,
					method: 'POST',
					data: params,
					success: (res) => {
						// console.log(res)
						if (res.data.data.group.name == '群聊') {
							this.name = res.data.data.group.name
						} else {
							this.name = res.data.data.member[1].show_name
							this.user_id = res.data.data.member[1].user_id
						}

					},
				})
			},
			// 聊天页面回退到消息中心
			backhomeindex() {
				uni.switchTab({
					url: "/pages/chip/index"
				})
			},
			// 聊天界面回车事件发送事件
			enter(e) {
				// console.log(e);
				this.valueInput = e.detail.value
				console.log(this.valueInput);
				if (this.valueInput == '') {
					console.log(1);
					uni.showToast({
						title: '请输入文字',
						icon: 'none'
					})
				} else {
					console.log(2);
					var params = {
						_token: uni.getStorageSync('im_token'),
						_agent_id: '1',
						content_type: 0,
						content: `{"text":"${this.valueInput}"}`,
						list_id: this.list_id,
					}
					uni.request({
						url: `http://im.ezongguan.com/im/message/textMsg`,
						method: 'POST',
						data: params,
						success: (res) => {
							console.log(res)
							if (this.socketOpen) {
								console.log("this.socketOpen", this.socketOpen)
								uni.sendSocketMessage({
									data: this.valueInput,
								})
								this.chatData()
							} else {
								console.log("this.socketOpen", this.socketOpen)
								uni.onSocketOpen(res => {
									this.socketOpen = true;
									uni.sendSocketMessage({
										data: this.valueInput,
									})
								})
								this.chatData()
							}
						},
					})
					this.value1 = ''
				}

			},
			// 表情包打开
			emoticon() {
				this.mix = !this.mix
				// this.showemoticon = !this.showemoticon
			},
			// 键盘事件
			input(e) {
				console.log(e.detail);
			},
		}
	}
</script>

<style lang="less" scoped>
	.emoticontext_one {
		width: 680rpx;
		// display: flex;
		flex-wrap: wrap;
		font-size: 48rpx;

	}

	.send {
		width: 90rpx;
		height: 56rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		background: #7c76f1;
		color: #fff;
		border-radius: 3px;
		font-size: 12px;
	}

	page {
		background-color: #FFF;
	}

	.selectitem {
		color: skyblue;
	}

	.selectitem1 {
		color: #000;
	}

	.numbersbox {
		background-color: #fff;

		image {
			width: 80rpx;
			height: 80rpx;
			margin-right: 20rpx;
		}
	}

	.diamondMall_head {
		position: fixed;
		top: 0;
		left: 0;
		z-index: 1000;
		width: 100%;
		height: 100rpx;
		background: #fff;
	}

	.mycustomer_head {
		width: 390rpx;
		text-align: center;
	}

	.mycustomer_bottom {
		width: 100%;
		// height: 100rpx;
		background-color: #fff;
		position: fixed;
		bottom: 0;
		left: 0;
	}
</style>
